#ifndef SDK_OHOS_OHOS_VIDEO_TRACK_H_
#define SDK_OHOS_OHOS_VIDEO_TRACK_H_

#include <memory>
#include <string>
#include <vector>
#include "api/ohos_video_track_interface.h"
#include "ohos_media_track.h"
#include "api/ohos_video_render_interface.h"
#include "api/media_stream_interface.h"
#include "rtc_base/logging.h"
#include "rtc_base/thread.h"
#include "api/ohos_video_render_interface.h"
#include "ohos_video_render_adapter.h"
#include "api/ohos_peer_connection_factory_interface.h"
#include "rtc_base/synchronization/mutex.h"

namespace ohoswebrtc {

class OHOSVideoTrack : public OHOSVideoTrackInterface {
  public:
    /** Initialize an OHOSVideoTrack from a native VideoTrackInterface. */
    OHOSVideoTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface> track, rtc::scoped_refptr<OHOSPeerConnectionFactoryInterface> peer_connection_factory);
    virtual ~OHOSVideoTrack();
    
    /**
    * The kind of track. For example, "audio" if this track represents an audio
    * track and "video" if this track represents a video track.
    */
    const std::string kind() const override { return kind_; }

    /** An identifier string. */
    const std::string id() const override { return id_; }

    /** The enabled state of the track. */
    bool enabled() const override { return track_->enabled(); }

    /** set enabled state of the track. */
    bool set_enabled(bool enable) override {
      return track_->set_enabled(enable);
    }

    /** The state of the track. */
    OHOSMediaTrackState state() const override {
      return static_cast<OHOSMediaTrackState>(track_->state());
    }

    /** Add video renderer */
    void AddRenderer(OHOSVideoRenderInterface* renderer) override;
    void RemoveRenderer(OHOSVideoRenderInterface* renderer) override;
    
    /**
    * The native MediaStreamTrackInterface(AudioTrackInterface) passed in or created during
    * construction.
    */
    rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track() override;

    rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track() override;
  
  private:
    rtc::scoped_refptr<webrtc::VideoTrackInterface> track_;
    rtc::Thread* worker_thread_;
    rtc::scoped_refptr<OHOSPeerConnectionFactoryInterface> peer_connection_factory_;
    std::vector<rtc::scoped_refptr<OHOSVideoRenderAdapter>> renderers_;
    std::string id_; 
    std::string kind_;
    std::unique_ptr<webrtc::Mutex> render_lock_;
};

}

#endif